const jwt = require('koa-jwt')
class BaseController{
    public auth = jwt({secret: 'secret'})
    ok (data:object) {
        return {
            code: 0,
            msg: 'success',
            data: data
        }
    }
    fail (data:object) {
        return {
            code: -1,
            msg: 'failed',
            data: data
        }
    }
    async checkOwner (ctx:any, next:any) {
        if (ctx.params.id !== ctx.state.user._id) {
            ctx.throw(403, '没有权限')
        }
        await next()
    }
}

module.exports = new BaseController()